Skip to content

Improve alignment in todo list output #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yzx9
Copy link

@yzx9 yzx9 commented Apr 25, 2025

Problem

The current task list output is not column-aligned, which makes it hard to visually scan — especially with variable-width fields like task ID, priority, and date/time. This becomes more noticeable with long or complex lists.

What’s implemented

I've put together a working prototype that aligns the key fields (ID, priority, date/time) for better readability.

The new implementation refactors the original rendering logic into three clear steps: format, optional align, and style, based on a column configuration. Each column defines how its value is formatted, optionally aligned, and styled. This design makes the output easier to manage and extend.

It’s also future-proof: we can easily support custom output formats (e.g. via a user-defined column template string) without changing the rendering pipeline.

Examples

› python -m todoman
[ ]  5   ! 2025-04-25 18:41 Masked content @work                   
[ ] 23  !! 2025-05-26 10:52 Masked content A @home                               
[ ] 25  !! 2025-04-25 09:00 Masked content ABC [project]            
[ ]  2 !!! 2025-04-25 22:30 Masked content ABCD @work                                
[ ] 20 !!! 2025-04-25 22:00 Masked content ABCDE @home 

› python -m todoman --humanize
[ ]  5   ! 3 hours ago    Masked content @work                   
[ ] 23  !! in 30 days     Masked content A @home                               
[ ] 25  !! 13 hours ago   Masked content ABC @home [project]            
[ ]  2 !!! in 5 minutes   Masked content ABCD @work                                
[ ] 20 !!! 24 minutes ago Masked content ABCDE @home  

› python -m todoman --align never
[ ] 5 ! 2025-04-25 18:41 Masked content @work
[ ] 23 !! 2025-05-26 10:52 Masked content A @home
[ ] 25 !! 2025-04-25 09:00 Masked content ABC @home @home [project]
[ ] 2 !!! 2025-04-25 22:30 Masked content ABCD @work
[ ] 20 !!! 2025-04-25 22:00 Masked content ABCDE @home

Next steps

If there's interest in this improvement, I’m happy to continue with the remaining parts — including tests, documentation, and polish.

close #575

todoman/cli.py Outdated
@@ -287,6 +290,17 @@ def formatter(self) -> formatters.Formatter:

@click.group(invoke_without_command=True)
@click_log.simple_verbosity_option()
@click.option(
"--align",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columns is a more obvious name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columns is still a bit confusing, especially if we plan to support customizable column formats in the future. How about renaming it to column-aligned?

@yzx9 yzx9 force-pushed the aligned-output branch 2 times, most recently from 8efbec1 to 05a1b2d Compare April 28, 2025 06:24
@yzx9
Copy link
Author

yzx9 commented Apr 28, 2025

Thanks for your review and interest in this PR! I’ve fixed the issues you mentioned, except for the naming.

I’d also like to add some tests. But it turns out the testing utility todo_factory has a bug — it generates random IDs, making the behavior non-deterministic.

@yzx9 yzx9 marked this pull request as ready for review April 28, 2025 12:34
Copy link
Member

@WhyNotHugo WhyNotHugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this on my current set of tasks, and each line has a lot of trailing whitespace. This whitespace flows onto the next line, and as a result, there's an empty line after each todo.

Here's an example:

[ ]  722    (no due date) set up prometheuis @todo                                                                                          
[ ]  803    (no due date) set up xmpp metrics to prometheus @todo                                                                           

Note all the empty spaces at the end of each line.

I think the issue is that ONE todo description is really long (not included in my copy-pasta), so all other are made equally long by appending spaces.

@yzx9
Copy link
Author

yzx9 commented Apr 29, 2025

@WhyNotHugo Thanks for testing! I’ve skipped adding spaces after the last column if it is left-aligned.

BTW, there are two spaces in your copy-paste because no priority was assigned to any of the todos. We could filter out these empty columns if you're interested. But it would change the current behavior, so I would prefer to handle it in a separate PR.

@WhyNotHugo
Copy link
Member

Performance impact seems reasonable. I'm sure we can refine later if needed.

Before:

> hyperfine -- python -m todoman 
Benchmark 1: python
  Time (mean ± σ):       9.6 ms ±   1.2 ms    [User: 7.4 ms, System: 2.2 ms]
  Range (min … max):     8.2 ms …  13.7 ms    322 runs

After:

Benchmark 1: python
  Time (mean ± σ):      16.1 ms ±   1.5 ms    [User: 13.3 ms, System: 2.8 ms]
  Range (min … max):    14.4 ms …  22.4 ms    183 runs

With 266 pending tasks and about 4k total files.


summary = f"{todo.summary} {self.format_database(todo.list)}{percent}"

# TODO: add spaces on the left based on max todos"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Author

@yzx9 yzx9 Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, I don't modify them. I think it's invalid now?

https://github.com/pimutils/todoman/blob/main/todoman%2Fformatters.py#L158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align task list output for improved readability
2 participants